using Common.Unity.Extensions.PropertyMapper.Testing.Objects;
using Common.Unity.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Testing.Core;

namespace Common.Unity.Extensions.PropertyMapper.Testing
{
	[TestClass]
	public class CollectionPropertyExpressionMappingTests : UnityContainerTestBase
	{
		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyChildrenCountMappedProperly()
		{
			EntityViewWithCollectionProperty view = Container.Resolve<EntityViewWithCollectionProperty>();
			EntityWithCollectionProperty entity = Container.Resolve<EntityWithCollectionProperty>( view );
			Assert.AreEqual( view.ChildViews.Count, entity.Children.Count );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyChildrenPropertiesMappedProperly()
		{
			EntityViewWithCollectionProperty view = Container.Resolve<EntityViewWithCollectionProperty>();
			EntityWithCollectionProperty entity = Container.Resolve<EntityWithCollectionProperty>( view );
			for ( int i = 0; i < entity.Children.Count; i++ )
			{
				Assert.AreEqual( view.ChildViews[i].ID, entity.Children[i].ID );
				Assert.AreEqual( view.ChildViews[i].Name, entity.Children[i].Name );
			}
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyEntityChildrenCountMappedProperly()
		{
			EntityWithCollectionProperty entity = Container.Resolve<EntityWithCollectionProperty>();
			EntityViewWithCollectionProperty view = Container.Resolve<EntityViewWithCollectionProperty>( entity );
			
			Assert.AreEqual( entity.Children.Count, view.ChildViews.Count );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void VerifyEntityChildrenPropertiesMappedProperly()
		{
			EntityWithCollectionProperty entity = Container.Resolve<EntityWithCollectionProperty>();
			EntityViewWithCollectionProperty view = Container.Resolve<EntityViewWithCollectionProperty>( entity );
			for ( int i = 0; i < view.ChildViews.Count; i++ )
			{
				Assert.AreEqual( entity.Children[i].ID, view.ChildViews[i].ID );
				Assert.AreEqual( entity.Children[i].Name, view.ChildViews[i].Name );
			}
		}
	}
}